Make gtk-im-context-none work
authorMatthias Clasen <mclasen@redhat.com>
Tue, 24 Feb 2015 03:00:55 +0000 (22:00 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 24 Feb 2015 03:06:02 +0000 (22:06 -0500)
This was added a few years ago, as a way to have _no_ im context
at all. But it didn't actually work. Make it work, and streamline
the handling of none by moving it all to gtkimmodule.c.

As part of this, add context to the translated names of all
im modules we ship.

16 files changed:
gtk/gtkimmodule.c
gtk/gtkimmulticontext.c
modules/input/imam-et.c
modules/input/imbroadway.c
modules/input/imcedilla.c
modules/input/imcyrillic-translit.c
modules/input/imime.c
modules/input/iminuktitut.c
modules/input/imipa.c
modules/input/immultipress.c
modules/input/imquartz.c
modules/input/imthai.c
modules/input/imti-er.c
modules/input/imti-et.c
modules/input/imviqr.c
modules/input/imxim.c

index 2122b10dcea976f1fb2994ac60a4a8e6deef8d6e..1a90a226b741adaf9bf300b6aa8d0ac20bb86663 100644 (file)
@@ -65,6 +65,7 @@
 #include "deprecated/gtkrc.h"
 
 #define SIMPLE_ID "gtk-im-context-simple"
+#define NONE_ID   "gtk-im-context-none"
 
 /**
  * GtkIMContextInfo:
@@ -520,7 +521,7 @@ compare_gtkimcontextinfo_name(const GtkIMContextInfo **a,
  *            The structures it points are statically allocated and should
  *            not be modified or freed.
  * @n_contexts: the length of the array stored in @contexts
- * 
+ *
  * List all available types of input method context
  */
 void
@@ -535,7 +536,23 @@ _gtk_im_module_list (const GtkIMContextInfo ***contexts,
 #endif
                GtkIMContextInfo simple_context_info = {
     SIMPLE_ID,
-    N_("Simple"),
+    NC_("input method menu", "Simple"),
+    GETTEXT_PACKAGE,
+#ifdef GTK_LOCALEDIR
+    GTK_LOCALEDIR,
+#else
+    "",
+#endif
+    ""
+  };
+
+  static
+#ifndef G_OS_WIN32
+         const
+#endif
+               GtkIMContextInfo none_context_info = {
+    NONE_ID,
+    NC_("input method menu", "None"),
     GETTEXT_PACKAGE,
 #ifdef GTK_LOCALEDIR
     GTK_LOCALEDIR,
@@ -561,19 +578,22 @@ _gtk_im_module_list (const GtkIMContextInfo ***contexts,
        */
       simple_context_info.domain_dirname = g_strdup (simple_context_info.domain_dirname);
       correct_localedir_prefix ((char **) &simple_context_info.domain_dirname);
+      none_context_info.domain_dirname = g_strdup (none_context_info.domain_dirname);
+      correct_localedir_prefix ((char **) &none_context_info.domain_dirname);
     }
 #endif
 
   if (n_contexts)
-    *n_contexts = (n_loaded_contexts + 1);
+    *n_contexts = n_loaded_contexts + 2;
 
   if (contexts)
     {
       GSList *tmp_list;
       int i;
-      
-      *contexts = g_new (const GtkIMContextInfo *, n_loaded_contexts + 1);
 
+      *contexts = g_new (const GtkIMContextInfo *, n_loaded_contexts + 2);
+
+      (*contexts)[n++] = &none_context_info;
       (*contexts)[n++] = &simple_context_info;
 
       tmp_list = modules_list;
@@ -583,12 +603,12 @@ _gtk_im_module_list (const GtkIMContextInfo ***contexts,
 
          for (i=0; i<module->n_contexts; i++)
            (*contexts)[n++] = module->contexts[i];
-         
+  
          tmp_list = tmp_list->next;
        }
 
-      /* fisrt element (Default) should always be at top */
-      qsort ((*contexts)+1, n-1, sizeof (GtkIMContextInfo *), (GCompareFunc)compare_gtkimcontextinfo_name);
+      /* first elements (Simple and None) should always be at top */
+      qsort ((*contexts)+2, n-2, sizeof (GtkIMContextInfo *), (GCompareFunc)compare_gtkimcontextinfo_name);
     }
 }
 
@@ -607,7 +627,10 @@ _gtk_im_module_create (const gchar *context_id)
 {
   GtkIMModule *im_module;
   GtkIMContext *context = NULL;
-  
+
+  if (strcmp (context_id, NONE_ID) == 0)
+    return NULL;
+
   if (!contexts_hash)
     gtk_im_module_initialize ();
 
@@ -625,12 +648,12 @@ _gtk_im_module_create (const gchar *context_id)
              context = im_module->create (context_id);
              g_type_module_unuse (G_TYPE_MODULE (im_module));
            }
-         
+
          if (!context)
            g_warning ("Loading IM context type '%s' failed", context_id);
        }
     }
-  
+
   if (!context)
      return gtk_im_context_simple_new ();
   else
@@ -694,6 +717,8 @@ lookup_immodule (gchar **immodules_list)
     {
       if (g_strcmp0 (*immodules_list, SIMPLE_ID) == 0)
         return SIMPLE_ID;
+      else if (g_strcmp0 (*immodules_list, NONE_ID) == 0)
+        return NONE_ID;
       else
        {
          gboolean found;
index 9d2a1ad0a2dae0c4247ae079581c72105a8606af..6422abe6faab1bd349676fe1bf5115ab466de073 100644 (file)
@@ -38,8 +38,6 @@
  */
 
 
-#define NONE_ID "gtk-im-context-none"
-
 struct _GtkIMMulticontextPrivate
 {
   GtkIMContext          *slave;
@@ -274,12 +272,12 @@ gtk_im_multicontext_get_slave (GtkIMMulticontext *multicontext)
 
       priv->context_id = g_strdup (get_effective_context_id (multicontext));
 
-      if (g_strcmp0 (priv->context_id, NONE_ID) == 0)
-        return NULL;
-
       slave = _gtk_im_module_create (priv->context_id);
-      gtk_im_multicontext_set_slave (multicontext, slave, FALSE);
-      g_object_unref (slave);
+      if (slave)
+        {
+          gtk_im_multicontext_set_slave (multicontext, slave, FALSE);
+          g_object_unref (slave);
+        }
     }
 
   return priv->slave;
@@ -618,19 +616,6 @@ gtk_im_multicontext_append_menuitems (GtkIMMulticontext *context,
   gtk_widget_show (menuitem);
   gtk_menu_shell_append (menushell, menuitem);
 
-  menuitem = gtk_radio_menu_item_new_with_label (group, C_("input method menu", "None"));
-  if (g_strcmp0 (priv->context_id_aux, NONE_ID) == 0)
-    gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem), TRUE);
-  g_object_set_data (G_OBJECT (menuitem), I_("gtk-context-id"), NONE_ID);
-  g_signal_connect (menuitem, "activate", G_CALLBACK (activate_cb), context);
-  gtk_widget_show (menuitem);
-  gtk_menu_shell_append (menushell, menuitem);
-  group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menuitem));
-  
-  menuitem = gtk_separator_menu_item_new ();
-  gtk_widget_show (menuitem);
-  gtk_menu_shell_append (menushell, menuitem);
-
   _gtk_im_module_list (&contexts, &n_contexts);
 
   for (i = 0; i < n_contexts; i++)
@@ -649,7 +634,7 @@ gtk_im_multicontext_append_menuitems (GtkIMMulticontext *context,
                   * GTK+. Input method may have a name in the GTK+
                   * message catalog.
                   */
-                 translated_name = _(contexts[i]->context_name);
+                 translated_name = C_("input method menu", contexts[i]->context_name);
                }
              else
                {
@@ -688,9 +673,8 @@ gtk_im_multicontext_append_menuitems (GtkIMMulticontext *context,
 #else
       translated_name = contexts[i]->context_name;
 #endif
-      menuitem = gtk_radio_menu_item_new_with_label (group,
-                                                    translated_name);
-      
+      menuitem = gtk_radio_menu_item_new_with_label (group, translated_name);
+
       if ((priv->context_id_aux &&
            strcmp (contexts[i]->context_id, priv->context_id_aux) == 0))
         gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem), TRUE);
@@ -704,10 +688,10 @@ gtk_im_multicontext_append_menuitems (GtkIMMulticontext *context,
           text = g_strdup_printf (C_("input method menu", "System (%s)"), translated_name);
           gtk_label_set_text (GTK_LABEL (label), text);
           g_free (text);
-        }     
+        }
+
       group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menuitem));
-      
+
       g_object_set_data (G_OBJECT (menuitem), I_("gtk-context-id"),
                         (char *)contexts[i]->context_id);
       g_signal_connect (menuitem, "activate",
index a45f580aecbe458a6d01beecded4d7a48ab374e7..f3d7628875c5222f8a91d375b30d493006ecc362 100644 (file)
@@ -449,7 +449,7 @@ am_et_init (GtkIMContextSimple *im_context)
 
 static const GtkIMContextInfo am_et_info = { 
   "am_et",                /* ID */
-  N_("Amharic (EZ+)"),     /* Human readable name */
+  NC_("input method menu", "Amharic (EZ+)"),     /* Human readable name */
   GETTEXT_PACKAGE,        /* Translation domain */
    GTK_LOCALEDIR,         /* Dir for bindtextdomain (not strictly needed for "gtk+") */
   "am"                    /* Languages for which this module is the default */
index d0394f3340cea1c63cd0d167fdf1e02c50b9c5b6..140aa0e8c616b4b500f841652340b5e96af9e811 100644 (file)
@@ -48,7 +48,7 @@ static GObjectClass *parent_class;
 static const GtkIMContextInfo imbroadway_info =
 {
   "broadway",      /* ID */
-  "Broadway",      /* Human readable name */
+  NC_("input method menu", "Broadway"),      /* Human readable name */
   GETTEXT_PACKAGE, /* Translation domain */
   GTK_LOCALEDIR,   /* Dir for bindtextdomain (not strictly needed for "gtk+") */
   "",              /* Languages for which this module is the default */
index 9b230f4227d04cc00d62c62a4ba1a3c6ed110ca1..74790b79cad5f463540cdc36fabb3fe4fe47155f 100644 (file)
@@ -87,7 +87,7 @@ cedilla_init (GtkIMContextSimple *im_context)
 
 static const GtkIMContextInfo cedilla_info = { 
   "cedilla",                      /* ID */
-  N_("Cedilla"),                   /* Human readable name */
+  NC_("input method menu", "Cedilla"), /* Human readable name */
   GETTEXT_PACKAGE,                /* Translation domain */
   GTK_LOCALEDIR,                  /* Dir for bindtextdomain */
   "az:ca:co:fr:gv:oc:pt:sq:tr:wa"  /* Languages for which this module is the default */
index 48a54355a14365106081ea35bbf6644198ece3b3..68b039248620dd00620a0e9c1d749f396172033c 100644 (file)
@@ -212,7 +212,7 @@ cyrillic_translit_init (GtkIMContextSimple *im_context)
 
 static const GtkIMContextInfo cyrillic_translit_info = { 
   "cyrillic_translit",            /* ID */
-  N_("Cyrillic (Transliterated)"), /* Human readable name */
+  NC_("input menthod menu", "Cyrillic (Transliterated)"), /* Human readable name */
   GETTEXT_PACKAGE,                /* Translation domain */
    GTK_LOCALEDIR,                 /* Dir for bindtextdomain (not strictly needed for "gtk+") */
   ""                              /* Languages for which this module is the default */
index 7bb5758bba9823cf7e1fb7d09d51fec9936ecc5e..d2943cf9cd410186abbbca7cb1bbb3d28c87884b 100644 (file)
@@ -27,8 +27,8 @@
 
 static const GtkIMContextInfo ime_info = {
   "ime",
-  "Windows IME",
-  "gtk+",
+  NC_("input method menu", "Windows IME"),
+  GETTEXT_PACKAGE,
   "",
   "ja:ko:zh",
 };
index 35fdb90d7eea99864de2f2276d3e83906c2f6f24..651e4beba22a385dbe0184c1c975f3f93d0e0083 100644 (file)
@@ -122,7 +122,7 @@ inuktitut_init (GtkIMContextSimple *im_context)
 
 static const GtkIMContextInfo inuktitut_info = { 
   "inuktitut",            /* ID */
-  N_("Inuktitut (Transliterated)"),         /* Human readable name */
+  NC_("input method menu", "Inuktitut (Transliterated)"), /* Human readable name */
   GETTEXT_PACKAGE,        /* Translation domain */
   GTK_LOCALEDIR,          /* Dir for bindtextdomain (not strictly needed for "gtk+") */
   "iu"                    /* Languages for which this module is the default */
index 24ac684d86ddefdc7f36aece0b7962b7a5de0640..efbc3bd2cb51943baeec2fed375b87f5df3fb711 100644 (file)
@@ -140,7 +140,7 @@ ipa_init (GtkIMContextSimple *im_context)
 
 static const GtkIMContextInfo ipa_info = { 
   "ipa",                  /* ID */
-  N_("IPA"),                       /* Human readable name */
+  NC_("input method menu", "IPA"), /* Human readable name */
   GETTEXT_PACKAGE,                /* Translation domain */
    GTK_LOCALEDIR,                 /* Dir for bindtextdomain (not strictly needed for "gtk+") */
   ""                              /* Languages for which this module is the default */
index c4c0202b28936c8ecfdfef364111a448a5851abf..89608cb1734e47a1f93170abfa5c93955b494727 100644 (file)
@@ -27,7 +27,7 @@
  */
 static const GtkIMContextInfo info = { 
   CONTEXT_ID,             /* ID */
-  N_("Multipress"),     /* Human readable name */
+  NC_("input method menu", "Multipress"),     /* Human readable name */
   GETTEXT_PACKAGE,        /* Translation domain. Defined in configure.ac */
   MULTIPRESS_LOCALEDIR,           /* Dir for bindtextdomain (not strictly needed for "gtk+"). Defined in the Makefile.am */
   ""                      /* Languages for which this module is the default */
index fa2afd3f813e13757e6753a6c60b78d4ec3cee21..5db6481f5c64bd2660d0b8cd00cd76370a3867d9 100644 (file)
@@ -55,7 +55,7 @@ static GObjectClass *parent_class;
 static const GtkIMContextInfo imquartz_info =
 {
   "quartz",
-  "Mac OS X Quartz",
+  NC_("input method menu", "Mac OS X Quartz"),
   GETTEXT_PACKAGE,
   GTK_LOCALEDIR,
   "ja:ko:zh:*",
index 586c0b81c7f485f04ee7ce477dc1af0230b70926..5a05a9a6eef2a42b4a5fbf792e85bf9942124164 100644 (file)
@@ -30,7 +30,7 @@ GType type_thai = 0;
 
 static const GtkIMContextInfo thai_info = { 
   "thai",         /* ID */
-  N_("Thai-Lao"),  /* Human readable name */
+  NC_("input method menu", "Thai-Lao"),  /* Human readable name */
   GETTEXT_PACKAGE, /* Translation domain */
   GTK_LOCALEDIR,   /* Dir for bindtextdomain (not strictly needed for "gtk+") */
   "lo:th"         /* Languages for which this module is the default */
index ec1af41afb13d361616fa3edfd46159b68b48bb2..a95ed60c7419e108e6e2cb08f477563af28ae62d 100644 (file)
@@ -448,7 +448,7 @@ ti_er_init (GtkIMContextSimple *im_context)
 
 static const GtkIMContextInfo ti_er_info = { 
   "ti_er",                /* ID */
-  N_("Tigrigna-Eritrean (EZ+)"),         /* Human readable name */
+  NC_("input method menu", "Tigrigna-Eritrean (EZ+)"), /* Human readable name */
   GETTEXT_PACKAGE,        /* Translation domain */
    GTK_LOCALEDIR,         /* Dir for bindtextdomain (not strictly needed for "gtk+") */
   "ti"                    /* Languages for which this module is the default */
index 23caadb2a7be73c477a0139a67b0e91187fde17f..0030020639ec59682da2464aaca570bf19a79674 100644 (file)
@@ -448,7 +448,7 @@ ti_et_init (GtkIMContextSimple *im_context)
 
 static const GtkIMContextInfo ti_et_info = { 
   "ti_et",                /* ID */
-  N_("Tigrigna-Ethiopian (EZ+)"),         /* Human readable name */
+  NC_("input method menu", "Tigrigna-Ethiopian (EZ+)"), /* Human readable name */
   GETTEXT_PACKAGE,        /* Translation domain */
    GTK_LOCALEDIR,         /* Dir for bindtextdomain (not strictly needed for "gtk+") */
   "ti"                    /* Languages for which this module is the default */
index f074b29082ac7ea57b5bc0aaa2578fe6177d1d8e..d9572f51ce4203ac5c6c21400d3b68748eaabc3b 100644 (file)
@@ -239,7 +239,7 @@ viqr_init (GtkIMContextSimple *im_context)
 
 static const GtkIMContextInfo viqr_info = { 
   "viqr",                 /* ID */
-  N_("Vietnamese (VIQR)"), /* Human readable name */
+  NC_("input method menu", "Vietnamese (VIQR)"), /* Human readable name */
   GETTEXT_PACKAGE,        /* Translation domain */
    GTK_LOCALEDIR,         /* Dir for bindtextdomain (not strictly needed for "gtk+") */
   "vi"                    /* Languages for which this module is the default */
index fd8f38bb5483567ca7dfbca91dbc8e2a1547fc87..aff332bdf172ef9e6d26a0cc5ad3cd80acdb2fdf 100644 (file)
@@ -23,7 +23,7 @@
 
 static const GtkIMContextInfo xim_ja_info = { 
   "xim",                          /* ID */
-  N_("X Input Method"),            /* Human readable name */
+  NC_("input method menu", "X Input Method"), /* Human readable name */
   GETTEXT_PACKAGE,                /* Translation domain */
   GTK_LOCALEDIR,                  /* Dir for bindtextdomain (not strictly needed for "gtk+") */
   "ko:ja:th:zh"                           /* Languages for which this module is the default */